//
//  PageViewLinkCell.swift
//  
//
//  Created by Ralf on 6/12/15.
//
//

import UIKit

class PageViewLinkCell: TableViewCell
{
    let __favorites_button_tag = 39
    let __buy_button_tag  = 40
    let __score_button_tag = 41
    
    @IBOutlet var addComment: UIButton!


    var articleId: String!

    override func awakeFromNib()
    {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func setData(data: NSMutableDictionary)
    {
        let article = data["article"] as! NSDictionary
        articleId = String(article["id"] as! Int)
        let numberOfRateOfPraise  = article["rateOfPraise"] as? Double
        let numberOfFavorites = article["numberOfFavorites"] as? Int
        
        let numberOfComment = article["numberOfComment"] as? Int
        
        let numberOfAppointment = article["numberOfAppointment"] as! Int
        
        let label = self.viewWithTag(__score_button_tag) as! UILabel
        label.textColor = Theme.score_color
        label.text = String(numberOfAppointment)+" 人购买过"
        
        if numberOfRateOfPraise != nil
        {
            setScoreButton(numberOfComment!)
        }

        if numberOfFavorites != nil
        {
            setFavoritesButton(numberOfFavorites!)
        }
        
    }

    func setScoreButton(numberOfComment: Int)
    {
        let button = self.viewWithTag(__score_button_tag) as! UILabel
        button.text = String(stringInterpolationSegment: numberOfComment)
    }

    func setFavoritesButton(numberOfFavorites: Int)
    {
        let button = self.viewWithTag(__favorites_button_tag) as! UILabel
        button.text = String(numberOfFavorites)+"人"
    }

    func getCommentsButton() -> UILabel
    {
        return self.viewWithTag(__score_button_tag) as! UILabel
        
    }

    @IBAction func go(sender: AnyObject)
    {
        let controller = CommentsViewController()
        controller.setData(articleId)
        self.pushViewController(controller)
    }
//    @IBAction func addComment(sender: UIButton)
//    {
//        let controller = CommentsViewController()
//        controller.setData(articleId)
//        self.pushViewController(controller)
//    }
}
